package com.ruoyi.exam.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.exam.domain.TextContent;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

import com.ruoyi.common.result.Result;

import com.ruoyi.exam.service.ITextContentService;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文本表 前端控制器
 * </p>
 *
 * @author JY
 * @since 2024-02-24
 */
@Api(tags ="文本表表")
    @RestController
@RequestMapping("/exam/text-content")
    public class TextContentController {
@Resource(name = "TextContentServiceImpl")
private ITextContentService textContentService;

/**
* 新增
*/
@PostMapping("/save")
@ApiOperation(value = "新增", notes = "新增")
@ApiImplicitParam(name = "textContent", value = "textContent实体类",dataTypeClass = String.class)
public Result<Boolean> insert(@RequestBody TextContent textContent){
        return Result.ok(textContentService.save(textContent));
        }

/**
* 修改
*/
@PostMapping("/update")
@ApiOperation(value = "修改", notes = "修改")
@ApiImplicitParam(name = "textContent", value = "textContent实体类",dataTypeClass = String.class)
public Result<Boolean>  update(@RequestBody TextContent textContent){
        return Result.ok(textContentService.updateById(textContent));
        }

/**
* 根据id删除
*/
@PostMapping("/delete/{id}")
@ApiOperation(value = "根据id删除", notes = "根据id删除")
@ApiImplicitParam(name = "id", value = "id",dataTypeClass = String.class)
public Result<Boolean>  delete(@PathVariable Integer id){
        return Result.ok(textContentService.removeById(id));
        }

/**
* 批量删除
*/
@PostMapping("/del/batch")
@ApiOperation(value = "批量删除", notes = "批量删除")
@ApiImplicitParam(name = "ids", value = "id数组",dataTypeClass = String.class)
public Result<Boolean>  deleteBatch(@RequestBody List<Integer> ids){
        return Result.ok(textContentService.removeByIds(ids));
        }

/**
* 查询全部
*/
@GetMapping("/getAll")
@ApiOperation(value = "查询全部", notes = "查询全部")
public Result<List<TextContent>> findAll(){
        return Result.ok(textContentService.list());
        }

/**
* 根据id查询一个
*/
@GetMapping("getById/{id}")
@ApiOperation(value = "根据id查询一个", notes = "根据id查询一个")
@ApiImplicitParam(name = "id", value = "id",dataTypeClass = Integer.class)
public Result<TextContent> findOne(@PathVariable Integer id){
        return Result.ok(textContentService.getById(id));
        }

/**
* 分页模糊查询
*/
@GetMapping("/get/page")
@ApiOperation(value = "分页模糊查询", notes = "分页模糊查询")
public Result<Page<TextContent>>findPage(@RequestParam Integer pageNum,
@RequestParam Integer pageSize){
        QueryWrapper<TextContent> queryWrapper=new QueryWrapper<>();
        // 倒序查询
        queryWrapper.orderByDesc("id");
        return Result.ok(textContentService.page(new Page<>(pageNum,pageSize),queryWrapper));
        }
        }

